package com.wxdc.nmgyt.nmgytwydc.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wxdc.nmgyt.nmgytwydc.R;
import com.wxdc.nmgyt.nmgytwydc.common.DoubleClickExit;
import com.wxdc.nmgyt.nmgytwydc.model.BASE_WORKFLOWCURRENT;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2018/11/28.
 */

public class AuditBackData_RecyclerviewAdapter extends RecyclerView.Adapter<AuditBackData_RecyclerviewAdapter.myHolder> implements View.OnClickListener,View.OnLongClickListener{
    private Context mContext;
    private List<BASE_WORKFLOWCURRENT> backDatas;
    private RecyclerViewOnItemClickListener mOnItemClickListener;
    private RecyclerViewOnLongClickListener mOnLongClickListener;
    public AuditBackData_RecyclerviewAdapter(Context context, List<BASE_WORKFLOWCURRENT> list) {
        mContext = context;
        backDatas = list;
    }

    public interface  RecyclerViewOnItemClickListener{
        void onItemClick(View view);
    }

    public interface  RecyclerViewOnLongClickListener{
        void onLongClick(int position);
    }

    @NonNull
    @Override
    public myHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater lf = LayoutInflater.from(mContext);
        View itemView  =  lf.inflate(R.layout.auditbackdata_recyclerview_item, parent, false);
        itemView.setOnClickListener(this);
        itemView.setOnLongClickListener(this);
        return new myHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull myHolder holder, int position) {
        BASE_WORKFLOWCURRENT obj = backDatas.get(position);
        holder.mView.setTag(position);
        holder.commitTxt.setTag(position);
        holder.bind(obj);
    }

    @Override
    public int getItemCount() {
        return backDatas == null ? 0 : backDatas.size();
    }

    @Override
    public void onClick(View v) {
        if (mOnItemClickListener != null) {
          //单击事件
          mOnItemClickListener.onItemClick(v);
        }
    }
    @Override
    public boolean onLongClick(View v) {
        if (mOnLongClickListener != null) {
            mOnLongClickListener.onLongClick((Integer) v.getTag());
        }
        return true;
    }

    //--------------------------------------------------------------------------------------
    class myHolder extends RecyclerView.ViewHolder {
        private View mView;
        private TextView jcdNameTxt;
        private TextView commitTxt;
        public myHolder(View itemView) {
            super(itemView);
            this.mView = itemView;
            jcdNameTxt = mView.findViewById(R.id.ad_rv_item_jcdname_txt);
            commitTxt = mView.findViewById(R.id.ad_rv_item_commit_txt);
            commitTxt.setOnClickListener(AuditBackData_RecyclerviewAdapter.this);
        }
        public void bind(BASE_WORKFLOWCURRENT obj){
            jcdNameTxt.setText(obj.getGEMNAME());
        }
    }
    //----------------------------------------------------------------------------------
    public void setItemClickListener(RecyclerViewOnItemClickListener recyclerViewOnItemClickListener){
        mOnItemClickListener = recyclerViewOnItemClickListener;
    }
    public void setItemLongClickListener(RecyclerViewOnLongClickListener recyclerViewOnLongClickListener){
        mOnLongClickListener = recyclerViewOnLongClickListener;
    }
}
